package com.glodon.paas.account.security.cas.ticket.support;

import org.jasig.cas.ticket.ExpirationPolicy;
import org.jasig.cas.ticket.TicketState;

/**
 * Set TTL for tickets.
 *
 * @author Don Li
 */
public final class RedisExpirationPolicy implements ExpirationPolicy {

    private int ttl;
    private int timesOfUse = -1;

    public void setTimesOfUse(int timesOfUse) {
        this.timesOfUse = timesOfUse;
    }

    public int getTtl() {
        return ttl;
    }

    public void setTtl(int ttl) {
        this.ttl = ttl;
    }

    @Override
    public boolean isExpired(TicketState ticketState) {
        if (timesOfUse > 0 && ticketState.getCountOfUses() >= timesOfUse) {
            return true;
        }
        return false;
    }
}
